package com.bac.utils;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bac.bacplatform.R;
import com.bac.javabeans.GasStationDetail;

public class GasListAdapter extends BaseAdapter {

	LayoutInflater inflater;
	ViewHoder viewHoder;
	List<GasStationDetail.Oil> oil;

	public GasListAdapter(Context context,List<GasStationDetail.Oil> oil) {
		inflater = LayoutInflater.from(context);
		this.oil = oil;
	}
	@Override
	public View getView(int i, View convertView, ViewGroup arg2) {
//		if(viewHoder == null){
			convertView = inflater.inflate(R.layout.gas_list, null);
			viewHoder = new ViewHoder();
			viewHoder.name = (TextView) convertView.findViewById(R.id.gas_name);
			viewHoder.money= (TextView) convertView.findViewById(R.id.gas_money);
//		}
		this.viewHoder.name.setText(oil.get(i).getName());
		this.viewHoder.money.setText(oil.get(i).getPrice().doubleValue()+"");
		
		return convertView;
	}
	
	class ViewHoder{
		TextView name;
		TextView money;
	}

	@Override
	public int getCount() {
		return oil.size();
	}
	
	@Override
	public Object getItem(int i) {
		return oil.get(i);
	}
	
	@Override
	public long getItemId(int i) {
		return i;
	}
}
